/**
 * 钱包相关接口的mock数据
 */

/**
 * 查询订单价格
 * @param {Object} data 查询参数
 * @returns {Object} 价格信息
 */
export function checkPrice(data) {
  const { chainId, icon, specId } = data
  
  // 模拟不同规格和币种的价格
  let price = '100.00'
  if (specId === 2) {
    price = '200.00'
  } else if (specId === 3) {
    price = '150.00'
  }
  
  // 如果是ETH，价格按照汇率转换
  if (icon === 'ETH') {
    price = (parseFloat(price) / 2000).toFixed(6) // 假设1ETH=2000USDT
  } else if (icon === 'BNB') {
    price = (parseFloat(price) / 300).toFixed(6) // 假设1BNB=300USDT
  }
  
  return {
    code: 0,
    message: '查询价格成功',
    data: {
      chainId,
      icon,
      specId,
      price
    }
  }
}

/**
 * 创建订单
 * @param {Object} data 订单数据
 * @returns {Object} 订单信息
 */
export function createOrder(data) {
  const { chainId, icon, specId, counts } = data
  
  // 模拟不同规格和币种的价格
  let usdtPrice = '100.00'
  let productName = '数字藏品A - 标准版'
  
  if (specId === 2) {
    usdtPrice = '200.00'
    productName = '数字藏品A - 豪华版'
  } else if (specId === 3) {
    usdtPrice = '150.00'
    productName = '数字藏品B - 标准版'
  }
  
  // 计算总价
  const totalUsdtAmount = (parseFloat(usdtPrice) * counts).toFixed(2)
  
  // 如果是ETH或BNB，价格按照汇率转换
  let payAmount = totalUsdtAmount
  if (icon === 'ETH') {
    payAmount = (parseFloat(totalUsdtAmount) / 2000).toFixed(6) // 假设1ETH=2000USDT
  } else if (icon === 'BNB') {
    payAmount = (parseFloat(totalUsdtAmount) / 300).toFixed(6) // 假设1BNB=300USDT
  }
  
  // 模拟合约地址
  let contractAddress = ''
  if (icon === 'USDT') {
    contractAddress = '0xdac17f958d2ee523a2206206994597c13d831ec7'
  } else if (icon === 'ETH') {
    contractAddress = '0x0000000000000000000000000000000000000000'
  } else if (icon === 'BNB') {
    contractAddress = '0x0000000000000000000000000000000000000000'
  }
  
  return {
    code: 0,
    message: '创建订单成功',
    data: {
      orderNo: 'ORD' + Date.now(),
      amount: totalUsdtAmount,
      payAmount,
      currency: icon,
      networkId: chainId,
      contractAddress,
      fromAddress: '0x1234567890abcdef1234567890abcdef12345678', // 用户地址
      toAddress: '0xabcdef1234567890abcdef1234567890abcdef12', // 平台收款地址
      productName,
      expried: Math.floor(Date.now() / 1000) + 3600 // 1小时后过期
    }
  }
}